package com.niubility.server.Impl;

import com.niubility.dao.DatasDao;
import com.niubility.entity.Datas;
import com.niubility.server.IDataServer;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service("dataServer")
@Transactional
public class DataServer implements IDataServer{
    @Resource
    private DatasDao datasDao;

    public List<Datas> LoadAll(int start,int num ,String type){
        return datasDao.LoadAllByMark(start,num,type);
    }

    public boolean Save(Datas dep) {
        return datasDao.Save(dep)>0 ? true:false;
    }

    public boolean Delete(int id) {
        return datasDao.Delete(id) > 0 ? true:false;
    }

    public Datas select(int id) {
        return datasDao.Select(id).get(0);
    }

    public int PageNumAll(){
        return datasDao.PageNumAll();
    };
    public int PageNumByType(int num,String type){
        int pagNum = datasDao.PageNumByType(type);
        int nums = pagNum%num;
        //System.out.println(nums);
        int LagerPage = nums == 0?pagNum/num: pagNum/num+1;
        return LagerPage;
    }

    public boolean Auto(int id){
        return datasDao.AutoIncreate(id)>0?true:false;
    }

    public int LastInsertId(){
        return datasDao.LastInsertId();
    }
    public List<Datas> LoadHot(int num){
        return datasDao.LoadHot(num);
    }
}
